const express = require('express');
const { routeWrapper } = require('../../../lib/module/tool/route');
const router = express.Router();

const productService = require('../../../lib/service/productService');

// 栏目列表
router.get('/:areaId/sectionList', routeWrapper(async (req) => {
    return productService.sectionList(req.params.areaId);
}, true));

// ======================================= 收藏业务 ===============================
// 收藏商品
router.get('/:areaId/collectProduct', routeWrapper(async (req) => {
    return productService.collectProduct(req.auth.userId, req.params.areaId, req.query.productId);
}, true));

// 查询商品是否被收藏
router.get('/:areaId/productHasCollected', routeWrapper(async (req) => {
    return productService.productHasCollected(req.auth.userId, req.params.areaId, req.query.productId);
}, true));

// 收藏列表
router.get('/:areaId/collectList', routeWrapper(async (req) => {
    return productService.collectList(req.auth.userId, req.params.areaId);
}, true));

// ======================================= 购物车业务 ===============================
// 加入购物车
router.post('/:areaId/addSkuToCart', routeWrapper(async (req) => {
    return productService.addSkuToCart(req.auth.userId, req.params.areaId, req.body.productId, req.body.skuId);
}, true));

// 减少购物车sku数量
router.post('/:areaId/subtractSkuFromCart', routeWrapper(async (req) => {
    return productService.subtractSkuFromCart(req.auth.userId, req.params.areaId, req.body.productId, req.body.skuId);
}, true));

// 查询购物车信息
router.get('/:areaId/cartInfo', routeWrapper(async (req) => {
    return productService.cartInfo(req.auth.userId, req.params.areaId);
}, true));

// 查询热力排行榜
router.get('/:areaId/heatLeaderboard', routeWrapper(async (req) => {
    return productService.heatLeaderboard(req.params.areaId);
}, false));

// 商品详情 查询随机商品
router.get('/:areaId/randomProduct/:size', routeWrapper(async (req) => {
    return productService.randomProduct(req.params.areaId, req.params.size);
}, false));
module.exports = router;
